package com.blockmeta.bbs.immodule.widget.chatboard;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Rect;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;

class InputFieldQueryPopup extends Dialog
{
	public interface onDismissListener
	{
		public void onDismiss();
	}
	public onDismissListener m_listenerOnDismiss;
	
	public int m_key;
	private View m_view;
	private boolean m_modal = false;

	public InputFieldQueryPopup(Context context, int theme)
	{
		super(context, theme);
	}

	public void setContentView(View view, FrameLayout.LayoutParams params, int gravity)
	{
		super.setContentView(view, params);

		this.m_view = getWindow().getDecorView();
		WindowManager.LayoutParams lp = getWindow().getAttributes();
		lp.gravity = gravity;
		lp.x = params.leftMargin;
		lp.y = params.topMargin;
		lp.width = params.width;
		lp.height = params.height;
		getWindow().setAttributes(lp);

		params.setMargins(0, 0, 0, 0);
		view.setLayoutParams(params);
	}

	public boolean onTouchEvent(MotionEvent event)
	{
		if (this.m_modal)
		{
			return super.onTouchEvent(event);
		}
		Rect outRect = new Rect();
		this.m_view.getHitRect(outRect);
		if (outRect.contains((int) event.getX(), (int) event.getY()))
		{
			return super.onTouchEvent(event);
		}
		outRect = null;
		dismiss();
		return true;
	}

	public void setModal()
	{
		this.m_modal = true;
	}
}
